package com.briup.smartcity.web.controller;

import com.briup.smartcity.aop.Logging;
import com.briup.smartcity.bean.Carousel;
import com.briup.smartcity.service.ICarouselService;
import com.briup.smartcity.service.impl.CarouseIServiceImpl;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;

@Api(tags = "轮播图模块")
@RestController
@RequestMapping("/auth/carousel")
public class CarouselController {
    @Autowired
    private ICarouselService service;
    @Logging()
    @ApiOperation("分页查找轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小", dataType = "int")
    })
    @GetMapping("/page/query")
    public Result findAllCarouse(Integer pageNum, Integer pageSize){
        PageInfo<Carousel> pageInfo = service.findAll(pageNum,pageSize);
        return ResultUtil.success(pageInfo);
    }

    @ApiOperation("添加轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carouselName", value = "图片名称", dataType = "String"),
            @ApiImplicitParam(name = "carouselInfo", value = "图片描述", dataType = "String"),
            @ApiImplicitParam(name = "carouselUrl", value = "图片地址", dataType = "String")
    })
    @PostMapping(value = "/save",consumes = "application/x-www-form-urlencoded")//
    public Result addCarousel(@ApiIgnore Carousel carousel ){
        //名称，地址，描述
        System.out.println(carousel.getCarouselId());
        System.out.println(carousel);
        service.saveCarousel(carousel);
        return ResultUtil.success();
    }
    @Autowired
    private CarouseIServiceImpl serviceImpl;
    @ApiOperation("删除轮播图(Id)")
    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        serviceImpl.deleteById(id);
        return ResultUtil.success();
    }

    @ApiOperation("查看启用轮播图")
    @GetMapping("find/yes")
    public Result selectyes(){
        List<Carousel> list = service.findYesCarousel();
        return ResultUtil.success(list);
    }

    @ApiOperation("更新轮播图状态")
    @PutMapping("/update")
    public Result updateCarousel(Carousel carousel){
        //1,接收到的参数值只有id，和状态
        //实现最少一张图处于启用状态
        service.updateCarousel(carousel);
        return ResultUtil.success();
    }
}
